<template>
<div class="all">
  <div class="right">
    <div v-for="index in Math.ceil($store.state.value.length/5)" 
      :key="index" :class="{on: $store.state.on==index}" 
      @click="paging(index)">
      {{index}}
    </div>
    <div v-if="Math.ceil($store.state.value.length/5) > 5">
      >>
    </div>
  </div>
  <div class="left">
    <span @click="search()">搜索|&nbsp;</span><input type="text" v-model="id" placeholder="请输入id查找">
  </div>
</div>
</template>


<script>
export default {
  methods:{
    paging(index){
      this.$store.state.min =0 + (index-1)*5
      this.$store.state.on = index
    },
    search(){
      if(this.show){
        this.show = false
        let id = Number(this.id)
        let index = this.$store.state.value.findIndex((elem)=>{
          return elem.id == id
        })
        if(index==-1){
          alert("没有这个数据")
          this.show = true
          this.id = ''
          return
        }
        let page = Math.ceil((index+1)/5)
        this.$store.state.onIndex = index
        setTimeout(()=>{
          this.$store.state.onIndex = -1
        }, 500)
        this.$store.state.min =0 + (page-1)*5
        this.$store.state.on = page
        this.id = ''
        this.show = true
      }
    }
  },
  data(){
    return {
      id: '',
      show: true
    }
  }
}
</script>

<style scoped>
.all{
  display: flex;
}
.right{
  display: flex;
}
.right div{
  width: 50px;
  text-align: center;
}
.left{
  flex-grow: 1;
  border: 1px solid;
  border-top: 0 solid;
  display: flex;
  align-items: center;
}
.left input{
  width: 100%;
  border: 0 solid;
  outline: none;
}
.left span{
  width: 10%;
  text-align: end;
  height: 20px;
  overflow: hidden;
}
</style>